﻿// the1stmovement
package com.reyco1.util
{
	/**
	 * Compilation of static functions which use regular expressions to validate a string
	 * @author reynaldo.columna
	 * 
	 */	
	public class ValidateUtil
	{
		/**
		 * Verifies that the string is not empty
		 * @param $content : content to be validated
		 * @return 
		 * 
		 */		
		public static function isNotEmpty($content:String):Boolean
		{
			var pattern:RegExp = /^\S{1,}$/
			return pattern.test($content);
		}
		
		/**
		 * Validates a name or last name
		 * @param $name : name to validate
		 * @return 
		 * 
		 */		
		public static function validName($name:String):Boolean
		{
			var pattern:RegExp = /^([a-zA-z\s]{3,})$/
			return pattern.test($name);
		}
		/**
		 * Validates a US state
		 * @param $state : State to validate
		 * @return 
		 * 
		 */
		public static function validState($state:String):Boolean
		{
			var pattern:RegExp = /^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]))$/i
			return pattern.test($state);
		}
		
		/**
		 * Validates a zip code
		 * @param $zipcode : zip code to validate
		 * @return 
		 * 
		 */		
		public static function validZip($zipcode:String):Boolean
		{
			var pattern:RegExp = /^\d{5}(-\d{4})?$/
			return pattern.test($zipcode);
		}
		
		/**
		 * Validates a phone number
		 * @param $phonenumber : phone number to validate
		 * @return 
		 * 
		 */		
		public static function validPhone($phonenumber:String):Boolean
		{
			var pattern:RegExp = /^(\([2-9]|[2-9])(\d{2}|\d{2}\))(-|.|\s)?\d{3}(-|.|\s)?\d{4}$/
			return pattern.test($phonenumber);
		}
		
		/**
		 * Validates an email
		 * @param $email : email to validate
		 * @return 
		 * 
		 */		
		public static function validEmail($email:String):Boolean
		{
			var pattern:RegExp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*/
			return pattern.test($email);
		}
	}
}